﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Skyhook.TransactionControl.Objects;

namespace TransactionControl.UnitTests {
    [TestClass]
    public class SimpleUnitTest : TestBase {
        [TestCleanup()]
        public override void Cleanup() {
            base.Cleanup();
        }

        /// <summary>
        /// Since I'm not actually testing any value I will be just watch that on exception the transaction rolls back.
        /// </summary>
        [TestMethod]
        public void TestTransactionCommit1() {
            ExampleObject1.DoWork("1");
            ExampleObject2.DoWork("2");
            ExampleObject3.DoWork("3");

            TransactionManager.Commit();
        }

        [TestMethod]
        public void TestTransactionCommit2() {
            ExampleObject1.DoWork("4");
            ExampleObject2.DoWork("5");
            ExampleObject3.DoWork("6");

            TransactionManager.Commit();
        }

        /// <summary>
        /// Test that we can do our asserts here but cleanup will ultimatly roll back everything.
        /// </summary>
        [TestMethod]
        public void TestTransactionRollbackOnCleanup() {
            ExampleObject1.DoWork("7");
            ExampleObject2.DoWork("8");
            ExampleObject3.DoWork("9");
        }


        [TestMethod]
        [ExpectedException(typeof(ApplicationException), "Value can not be empty!")]
        public void TestTransactionRollbackOnException() {
            ExampleObject1.DoWork();
            ExampleObject2.DoWork("");      // Will throw ApplictionException
            ExampleObject3.DoWork();

            TransactionManager.Commit();
        }
    }
}
